package com.findviewbydream.evil.helloyouth.Utils.SuperToast;

import android.app.Activity;
import android.os.Parcelable;
import android.view.View;

import com.github.johnpersano.supertoasts.*;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.OnDismissWrapper;
import com.github.johnpersano.supertoasts.util.Style;

/********************************************
 * 工程名：HelloYouth
 * 包名：com.findviewbydream.evil.helloyouth.Utils.SuperToast
 * 时间：16-6-9 下午7:15
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：超级提示窗（按钮） 工具类
 ********************************************/
public class ButtonToast
{
    private SuperActivityToast superActivityToast;

    private Activity activity;

    private String text = "";
    private String buttonText = "确认";
    private int buttonIcon = 0;
    private boolean touchDismiss = true;

    private Duration duration = Duration.NORMAL;
    private Background background = Background.GREEN;
    private Animations animations = Animations.FLYIN;
    private DarkIcon darkIcon = null;
    private LightIcon lightIcon = null;


    public ButtonToast(Activity activity)
    {
        this.activity = activity;
        superActivityToast = new SuperActivityToast(activity, SuperToast.Type.BUTTON);
    }


    public ButtonToast show()
    {
        if (!text.equals(""))
            superActivityToast.setText(text);

        if (buttonIcon == 0)
            superActivityToast.setButtonText(buttonText);
        else
            superActivityToast.setButtonIcon(buttonIcon, buttonText);

        superActivityToast.setTouchToDismiss(touchDismiss);

        if (lightIcon != null)
            switchLightIcon();

        if (darkIcon != null)
            switchDarkIcon();

        switchDuration();
        switchBackground();
        switchAnimations();

        superActivityToast.show();
        return this;
    }

    /**
     * 按钮点击事件
     *
     * @param onClick
     * @return
     */
    public ButtonToast setOnClick(OnClick onClick)
    {
        superActivityToast.setOnClickWrapper(
                new OnClickWrapper(activity + "", onClick));
        return this;
    }

    /**
     * 触摸消失事件
     *
     * @param touchDismissClick
     * @return
     */
    public ButtonToast setTouchDismissClick(TouchDismissClick touchDismissClick)
    {
        superActivityToast.setOnDismissWrapper(
                new OnDismissWrapper(activity + "", touchDismissClick));
        return this;
    }

    public enum Duration
    {
        MAX, LONG, SHORT, NORMAL
    }

    public enum Background
    {
        BLACK, BLUE, GRAY, GREEN, ORANGE, PURPLE, RED, WHITE
    }

    public enum Animations
    {
        FADE, FLYIN, SCALE, POPUP
    }

    public enum DarkIcon
    {
        输入, 退出, 警告, 重试, 刷新, 保存, 分享, 取消
    }

    public enum LightIcon
    {
        输入, 退出, 警告, 重试, 刷新, 保存, 分享, 取消
    }


    private void switchDuration()
    {
        switch (duration)
        {
            case NORMAL:
                superActivityToast.setDuration(2000);
                break;
            case SHORT:
                superActivityToast.setDuration(1000);
                break;
            case LONG:
                superActivityToast.setDuration(5000);
                break;
            case MAX:
                superActivityToast.setDuration(Integer.MAX_VALUE);
                break;
        }

    }

    private void switchBackground()
    {
        switch (background)
        {
            case BLACK:
                superActivityToast.setBackground(SuperToast.Background.BLACK);
                break;
            case GRAY:
                superActivityToast.setBackground(SuperToast.Background.GRAY);
                break;
            case BLUE:
                superActivityToast.setBackground(SuperToast.Background.BLUE);
                break;
            case GREEN:
                superActivityToast.setBackground(SuperToast.Background.GREEN);
                break;
            case ORANGE:
                superActivityToast.setBackground(SuperToast.Background.ORANGE);
                break;
            case PURPLE:
                superActivityToast.setBackground(SuperToast.Background.PURPLE);
                break;
            case RED:
                superActivityToast.setBackground(SuperToast.Background.RED);
                break;
            case WHITE:
                superActivityToast.setBackground(SuperToast.Background.WHITE);
                break;
        }
    }

    private void switchAnimations()
    {
        switch (animations)
        {
            case FADE:
                superActivityToast.setAnimations(SuperToast.Animations.FADE);
                break;
            case FLYIN:
                superActivityToast.setAnimations(SuperToast.Animations.FLYIN);
                break;
            case POPUP:
                superActivityToast.setAnimations(SuperToast.Animations.POPUP);
                break;
            case SCALE:
                superActivityToast.setAnimations(SuperToast.Animations.SCALE);
                break;
        }
    }

    private void switchDarkIcon()
    {
        switch (darkIcon)
        {
            case 输入:
                superActivityToast.setButtonIcon(SuperToast.Icon.Dark.EDIT);
                break;
            case 退出:
                superActivityToast.setButtonIcon(SuperToast.Icon.Dark.EXIT);
                break;
            case 警告:
                superActivityToast.setButtonIcon(SuperToast.Icon.Dark.INFO);
                break;
            case 重试:
                superActivityToast.setButtonIcon(SuperToast.Icon.Dark.REDO);
                break;
            case 刷新:
                superActivityToast.setButtonIcon(SuperToast.Icon.Dark.REFRESH);
                break;
            case 保存:
                superActivityToast.setButtonIcon(SuperToast.Icon.Dark.SAVE);
                break;
            case 分享:
                superActivityToast.setButtonIcon(SuperToast.Icon.Dark.SHARE);
                break;
            case 取消:
                superActivityToast.setButtonIcon(SuperToast.Icon.Dark.UNDO);
                break;
        }
    }

    private void switchLightIcon()
    {
        switch (lightIcon)
        {
            case 输入:
                superActivityToast.setButtonIcon(SuperToast.Icon.Light.EDIT);
                break;
            case 退出:
                superActivityToast.setButtonIcon(SuperToast.Icon.Light.EXIT);
                break;
            case 警告:
                superActivityToast.setButtonIcon(SuperToast.Icon.Light.INFO);
                break;
            case 重试:
                superActivityToast.setButtonIcon(SuperToast.Icon.Light.REDO);
                break;
            case 刷新:
                superActivityToast.setButtonIcon(SuperToast.Icon.Light.REFRESH);
                break;
            case 保存:
                superActivityToast.setButtonIcon(SuperToast.Icon.Light.SAVE);
                break;
            case 分享:
                superActivityToast.setButtonIcon(SuperToast.Icon.Light.SHARE);
                break;
            case 取消:
                superActivityToast.setButtonIcon(SuperToast.Icon.Light.UNDO);
                break;
        }
    }


    public ButtonToast setText(String text)
    {
        this.text = text;
        return this;
    }

    public ButtonToast setButtonText(String buttonText)
    {
        this.buttonText = buttonText;
        return this;
    }

    public ButtonToast setButtonIcon(int buttonIcon)
    {
        this.buttonIcon = buttonIcon;
        return this;
    }

    public ButtonToast setButtonIcon(DarkIcon darkIcon)
    {
        this.darkIcon = darkIcon;
        return this;
    }

    public ButtonToast setButtonIcon(LightIcon lightIcon)
    {
        this.lightIcon = lightIcon;
        return this;
    }

    public ButtonToast setDuration(Duration duration)
    {
        this.duration = duration;
        return this;
    }

    public ButtonToast setBackgroundColor(Background background)
    {
        this.background = background;
        return this;
    }

    public ButtonToast setAnimations(Animations animations)
    {
        this.animations = animations;
        return this;
    }

    public ButtonToast setTouchToDismiss(boolean touchDismiss)
    {
        this.touchDismiss = touchDismiss;
        return this;
    }


}
